package com.flink.flinkdemo.reduce;

import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.api.java.tuple.Tuple2;

/**
 * @author zhangy on 2021/1/2
 * @description: add you description
 */
public class MyReduceFunction implements ReduceFunction<Tuple2<String, Integer>> {

    @Override
    public Tuple2<String, Integer> reduce(Tuple2<String, Integer> value1, Tuple2<String, Integer> value2) throws Exception {
        if(value1.f0.equals(value2.f0)){
            return new Tuple2<>(value1.f0,value1.f1+value2.f1);
        }
        return new Tuple2<>(value2.f0,value2.f1);
    }
}